﻿using System;
using System.IO.Compression;
using System.IO;
using System.Text;


namespace Dotnet.Utils.Utility.EncryptUtil
{
    public static class SnappyCompressor
    {
        //参考项目地址：https://github.com/jeffesp/Snappy.Sharp

        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string CompressStringToBase64(string str)
        {
            var bytes = Encoding.UTF8.GetBytes(str);
            return Convert.ToBase64String(Snappy.Sharp.Snappy.Compress(bytes));
        }

        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string DecompressStringFromBase64(string str)
        {
            byte[] bytes = Convert.FromBase64String(str);
            return Encoding.UTF8.GetString(Snappy.Sharp.Snappy.Decompress(bytes));
        }
    }
}
